<?php

declare(strict_types=1);

namespace App\Model;

use Hyperf\DbConnection\Model\Model;

/**
 *  主播黑名单
 */
class HostBlacklist extends Model
{
    protected $table = 'host_blacklist';
    protected $fillable = ['user_id', 'flag'];

    static function getHostIds()
    {
        return self::where('flag', 1)->pluck('user_id')->toArray();
    }

    static function addHost($userId = 0)
    {
        return self::updateOrCreate(['user_id' => $userId], ['user_id' => $userId, 'flag' => 1]);
    }

    static function removeHost($userId = 0)
    {
        return self::updateOrCreate(['user_id' => $userId], ['user_id' => $userId, 'flag' => 0]);
    }

    /**
     * 是否在主播黑名单
     */
    static function checkBlack($userId = 0)
    {
        return self::where(['user_id' => $userId, 'flag' => 1])->count() > 0;
    }
}
